//
//  HelpViewController.m
//  TestARC
//
//  Created by 晓泉 吴 on 12-9-22.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "HelpViewController.h"
#import "AboutDetailViewController.h"
#import "HelpDetailViewController.h"

@interface HelpViewController ()

@end

@implementation HelpViewController
@synthesize helpArray,helpTableView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.navigationItem.title=@"帮助";
    self.helpArray = [NSMutableArray arrayWithCapacity:10];
    [self addRoundBound:self.helpTableView];
    
    
    
    // Find out the path of recipes.plist
    NSString *path = [[NSBundle mainBundle] pathForResource:@"helps" ofType:@"plist"];
    
    // Load the file content and read the data into arrays
    NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
    self.helpArray = [dict objectForKey:@"helpArray"];
    [self.helpTableView reloadData];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.helpArray = nil;
    self.helpTableView = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.helpArray count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
    UITableViewCell *cell = nil;
    NSInteger row;
    
    cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
    if (cell==nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
                                     reuseIdentifier:SimpleTableIdentifier];
    }
    row = [indexPath row];
    cell.textLabel.text = [[self.helpArray objectAtIndex:row]objectForKey:@"name"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.font = [UIFont systemFontOfSize:17.0f];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //填装详细视图的内容。 
    
    HelpDetailViewController * detailController = [[HelpDetailViewController alloc]initWithNibName:@"HelpDetailViewController" bundle:nil];
    
    int row = [indexPath row];
    //NSLog(@"选择了 %d 行",row);
    NSDictionary *helper;
    helper = [self.helpArray objectAtIndex:row];
    detailController.title = [helper objectForKey:@"name"];
    detailController.img =  [helper objectForKey:@"img"];
    
    [self.navigationController pushViewController:detailController animated:YES];
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


@end
